package com.liqi.web.controller.info;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.liqi.common.annotation.Log;
import com.liqi.common.core.controller.BaseController;
import com.liqi.common.core.domain.AjaxResult;
import com.liqi.common.enums.BusinessType;
import com.liqi.info.domain.TInfoZxzc;
import com.liqi.info.service.ITInfoZxzcService;
import com.liqi.common.utils.poi.ExcelUtil;
import com.liqi.common.core.page.TableDataInfo;

/**
 * 最新政策Controller
 * 
 * @author ruoyi
 * @date 2022-11-10
 */
@Api(tags = "政策服务信息")
@RestController
@RequestMapping("/info/TInfoZxzc")
public class TInfoZxzcController extends BaseController
{
    @Autowired
    private ITInfoZxzcService tInfoZxzcService;

    /**
     * 查询最新政策列表
     */
    @PreAuthorize("@ss.hasPermi('info:TInfoZxzc:list')")
    @ApiOperation("最新政策list")
    @GetMapping("/list")
    public TableDataInfo list(TInfoZxzc tInfoZxzc)
    {
        startPage();
        List<TInfoZxzc> list = tInfoZxzcService.selectTInfoZxzcList(tInfoZxzc);
        return getDataTable(list);
    }

    /**
     * 导出最新政策列表
     */
    @PreAuthorize("@ss.hasPermi('info:TInfoZxzc:export')")
    @Log(title = "最新政策", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TInfoZxzc tInfoZxzc)
    {
        List<TInfoZxzc> list = tInfoZxzcService.selectTInfoZxzcList(tInfoZxzc);
        ExcelUtil<TInfoZxzc> util = new ExcelUtil<TInfoZxzc>(TInfoZxzc.class);
        util.exportExcel(response, list, "最新政策数据");
    }

    /**
     * 获取最新政策详细信息
     */
    @PreAuthorize("@ss.hasPermi('info:TInfoZxzc:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tInfoZxzcService.selectTInfoZxzcById(id));
    }

    /**
     * 新增最新政策
     */
    @PreAuthorize("@ss.hasPermi('info:TInfoZxzc:add')")
    @Log(title = "最新政策", businessType = BusinessType.INSERT)
    @ApiOperation("新增")
    @PostMapping
    @Transactional
    public AjaxResult add(@RequestBody TInfoZxzc tInfoZxzc)
    {
        for (String systemType : tInfoZxzc.getSystemType().split(",")) {
            tInfoZxzc.setSystemType(systemType.trim());
            tInfoZxzc.setCreateUserId(getUserId().toString());
            tInfoZxzc.setDeptId(getDeptId().toString());
            tInfoZxzc.setCreateBy(getUsername());
            tInfoZxzc.setUpdateBy(getUsername());
            tInfoZxzcService.insertTInfoZxzc(tInfoZxzc);
        }
        return AjaxResult.success("新增政策成功");
    }

    /**
     * 修改最新政策
     */
    @PreAuthorize("@ss.hasPermi('info:TInfoZxzc:edit')")
    @Log(title = "最新政策", businessType = BusinessType.UPDATE)
    @ApiOperation("更新")
    @PutMapping
    @Transactional
    public AjaxResult edit(@RequestBody TInfoZxzc tInfoZxzc)
    {
        for (String systemType : tInfoZxzc.getSystemType().split(",")) {
            tInfoZxzc.setSystemType(systemType.trim());
            tInfoZxzc.setCreateUserId(getUserId().toString());
            tInfoZxzc.setDeptId(getDeptId().toString());
            tInfoZxzc.setCreateBy(getUsername());
            tInfoZxzc.setUpdateBy(getUsername());
            if(tInfoZxzcService.getByIdAndSystemType(String.valueOf(tInfoZxzc.getId()),tInfoZxzc.getSystemType()) > 0){
                tInfoZxzcService.updateTInfoZxzc(tInfoZxzc);
            }else {
                tInfoZxzcService.insertTInfoZxzc(tInfoZxzc);
            }
        }
        return AjaxResult.success("修改成功");
    }

    /**
     * 删除最新政策
     */
    @PreAuthorize("@ss.hasPermi('info:TInfoZxzc:remove')")
    @Log(title = "最新政策", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tInfoZxzcService.deleteTInfoZxzcByIds(ids));
    }
}
